﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
namespace DataAccess
{
    public class InfoDeTai
    {
        private string _MaDT;

        public string MaDT
        {
            get { return _MaDT; }
            set { _MaDT = value; }
        }
        private string _TenDT;

        public string TenDT
        {
            get { return _TenDT; }
            set { _TenDT = value; }
        }
        private int _SoLuongSV;

        public int SoLuongSV
        {
            get { return _SoLuongSV; }
            set { _SoLuongSV = value; }
        }
        private string _LamDoAn_KhoaLuan;

        public string LamDoAn_KhoaLuan
        {
            get { return _LamDoAn_KhoaLuan; }
            set { _LamDoAn_KhoaLuan = value; }
        }
        private string _MaNganh;

        public string MaNganh
        {
            get { return _MaNganh; }
            set { _MaNganh = value; }
        }
        public string Nganh
        {
            get
            {
                try
                {
                    return InfoNganh.TimTheoMaNganh(this.MaNganh)[0].TenNganh;
                }
                catch
                {
                    return "";
                }
            }
        }
        private string _MaGV;

        public string MaGV
        {
            get { return _MaGV; }
            set { _MaGV = value; }
        }
        public string GiaoVien
        {
            get
            {
                try
                {
                    return InfoGiaoVien.TimKiemTheoMaGV(this.MaGV)[0].HoTenGV;
                }
                catch
                {
                    return "";
                }
            }
        }
        public InfoDeTai()
        { }
        public static List<InfoDeTai> DanhSachDeTai()
        {
            return CBO.FillCollection<InfoDeTai>(DataProvider.Instance.ExecuteReader("DeTai_Select"));
        }
        //Thenm mot de tai
        public static int AddDeTai(InfoDeTai infodetai)
        {
            return DataProvider.Instance.ExecuteNonquery("DeTai_Add", infodetai.MaDT, infodetai.TenDT, infodetai.SoLuongSV, infodetai.LamDoAn_KhoaLuan, infodetai.MaGV, infodetai.MaNganh);
        }
        //Xoa mot de tai
        public static int DeleteDeTai(string madetai)
        {
            return DataProvider.Instance.ExecuteNonquery("DeTai_Delete", madetai);
        }
        //Update mot de tai
        public static int UpdateDeTai(InfoDeTai detai)
        {
            return DataProvider.Instance.ExecuteNonquery("DeTai_Update", detai.MaDT, detai.TenDT, detai.SoLuongSV, detai.LamDoAn_KhoaLuan, detai.MaGV, detai.MaNganh);
        }
        
        //////Tim kiem
        // Tim kiem theo ma detai
        public static List<InfoDeTai> TimKiemTheoMaDeTai(string ma)
        {
            return CBO.FillCollection<InfoDeTai>(DataProvider.Instance.ExecuteReader("DeTai_TimKiemMa", ma));
        }
        //Tim kiem theo detai
        public static List<InfoDeTai> TimKiemTheoHoTenDoAn(string doankhoaluan)
        {
            return CBO.FillCollection<InfoDeTai>(DataProvider.Instance.ExecuteReader("DeTai_TimKiemDoAnKhoaLuan", doankhoaluan));
        }
        public static List<InfoDeTai> TimKiemTheoNganh(string nganh)
        {
            return CBO.FillCollection<InfoDeTai>(DataProvider.Instance.ExecuteReader("DeTai_TimKiemTenNganh", nganh));
        }
        public static List<InfoDeTai> TimKiemTheoHoTenGiaoVien(string giaovien)
        {
            return CBO.FillCollection<InfoDeTai>(DataProvider.Instance.ExecuteReader("DeTai_TimKiemTenGiaoVien", giaovien));
        }


        //////////Thong ke
        // Thong ke so luong gia vien theo ma
        public static int ThongKeTheoMaDT()
        {
            object result = DataProvider.Instance.ExecuteScalar("DeTai_ThongKeMa");
            return Convert.ToInt32(result);
        }
        //Thong ke theo ho ten
        public static int ThongKeTheoDoAnKhoaLuan(string doankhoaluan)
        {
            object result = DataProvider.Instance.ExecuteScalar("DeTai_ThongKeDoAnKhoaLuan", doankhoaluan);
            return Convert.ToInt32(result);
        }

        //Thong ke theo ho ten
        public static int ThongKeTheoTenNganh1(string tennganh)
        {
            object result = DataProvider.Instance.ExecuteScalar("DeTai_ThongKeNganh", tennganh);
            return Convert.ToInt32(result);
        }

        //Thong ke theo ho ten
        public static int ThongKeTheoTenGiaoVien1(string tengv)
        {
            object result = DataProvider.Instance.ExecuteScalar("DeTai_ThongKeGiaoVien", tengv);
            return Convert.ToInt32(result);
        }
    }
}
